window.deviceUtils = {};
//设备操作
(function (utils) {
  utils.log = function (str) {
    console.info(str);
  };
  //获取平台标志
  utils.platfrom = {
    Android: (function () {
      return navigator.userAgent.match(/Android/i) ? true : false;
    })(),
    iOS: (function () {
      return navigator.userAgent.match(/iPhone|iPad|iPod/i) ? true : false;
    })(),
  };

  var setupWebViewJavascriptBridge = function (callback) {
    if (window.WebViewJavascriptBridge) {
      return callback(WebViewJavascriptBridge);
    }
    if (window.WVJBCallbacks) {
      return window.WVJBCallbacks.push(callback);
    }
    window.WVJBCallbacks = [callback];
    var WVJBIframe = document.createElement("iframe");
    WVJBIframe.style.display = "none";
    // if(getQueryVariable('source') == "CBIT" || getQueryVariable('channel') == "W"){
    //   WVJBIframe.src = ''
    // }else{
    //   WVJBIframe.src = "wvjbscheme://__BRIDGE_LOADED__";
    // }
    WVJBIframe.src = "wvjbscheme://__BRIDGE_LOADED__";
    document.documentElement.appendChild(WVJBIframe);
    setTimeout(function () {
      document.documentElement.removeChild(WVJBIframe);
    }, 0);
  };

 

  //JS调壳
  var callDevice = function (params, funName, callback) {
    try {
      var _bindBridge_device = function (bridge) {
        bridge.callHandler(funName, params, function responseCallback(responseData) {
          // console.log('JS received response:' + responseData);
          callback && callback(responseData);
        });
      };
      setupWebViewJavascriptBridge(_bindBridge_device);
    } catch (err) {
      // console.log('调设备方法发生异常错误(callDevice)：' + err.toString());
    }
  };
 
 
  
  utils.downloadQR=function(url, fileName, callBack = () => { }) {
    const params = {
      downLodURL:url,
      pdfName:fileName
    };
      callDevice(params, 'downloadPdf');
      callBack();
  }

  utils.shareWX = function(title, content,shareUrl,imageUrl, callBack = () => { }){
    console.log(title, content,shareUrl,imageUrl)
    const params = {
      title,
      content,
      shareUrl,
      imageUrl,
    };
  
    callDevice(params, 'shareWX');
    callBack();
  }

  // base64图片分享
  utils.shareWXImage = function(title, content,shareUrl,imageUrl,type,imageSource, callBack = () => { }){
    const params = {
      title,
      content,
      shareUrl,
      imageUrl,
      type,
      imageSource,
    };
  
    callDevice(params, 'shareWXImage');
    callBack();
  }
 

  utils.callDevice = callDevice;

})(window.deviceUtils);
var reb = window.deviceUtils.shareWX()
var rebDownloadQR = window.deviceUtils.downloadQR()
export { reb, rebDownloadQR }
//使用方式 window.deviceUtils.shareWX()